<template>
	<view class="content">
		<view class="title">重置密码</view>
		<view class="input">{{userInfo.areaCode}}:{{userInfo.account}}</view>
		<uni-easyinput type="password" class="input" :inputBorder="false" suffixIcon="eye" v-model="password"
			placeholder="请输入密码" ></uni-easyinput>
		<uni-easyinput type="password" class="input" :inputBorder="false" suffixIcon="eye" v-model="secondPwd"
			placeholder="请再次输入密码" ></uni-easyinput>
		<view class="tips">密码长度8-64位，数字、字母和符号组成。允许符号：@$!%*?&#(){}?/.,;:-  &gt; </view>
		<view class="next radius-btn" @click="nextAction">确认重置</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				isMobile:1,
				password:'',
				secondPwd:'',
				areaCode:'',
				account:'',
				code:'',
				userInfo:{}
			}
		},
		onLoad(opt) {
			this.userInfo = JSON.parse(opt.data)
			this.isMobile = this.userInfo.isMobile
		},
		methods:{
			//重置
			nextAction(){
				const regex = /^(?=.*\d)(?=.*[a-zA-Z])(?=.*[@$!%*?&#(){}?/.<>,;:-])[a-zA-Z\d@$!%*?&#().{}?/<>,;:-]{8,64}$/;
				if(!this.password || !this.secondPwd){
					uni.showToast({
						title:'密码不得为空',
						 icon:'none'
					})
					return
				} 
				if(!regex.test(this.password) || !regex.test(this.secondPwd)){
					uni.showToast({
						title:'密码为长度8-64位，数字、字母和符号组成',
						 icon:'none'
					})
					return
				} 
				if(this.password!==this.secondPwd){
					uni.showToast({
						title:'两次密码不一致',
						 icon:'none'
					})
					return
				}
				let data = {
					id:this.userInfo.userId,
					verCode:this.userInfo.code,
					newPass:this.password,
					confirmPass:this.secondPwd
				}
				uni.showLoading({
					title:this.$t('General.login.resetting'),
				})
				if(this.isMobile){
					data.phone = this.userInfo.account
					this.phoneResetPassword(data)
				}else{
					data.mail = this.userInfo.account
					this.mailResetPassword(data)
				} 
				
			},
			
			//手机找回密码
			phoneResetPassword(data){
				getApp().globalData.api.phoneResetPassword(data, (result) => {
					uni.hideLoading();
					uni.navigateBack({delta:3})
				});
			},
			//邮箱找回密码
			mailResetPassword(data){
				getApp().globalData.api.mailResetPassword(data, (result) => {
					uni.hideLoading();
					uni.navigateBack({delta:3})
				});
			},
			
		}
		
	}
</script>

<style lang="scss" scoped>
	.content{
		padding: 40rpx;
		.title{
			font-size: 30rpx;
			font-weight: 700;
			margin-bottom: 50rpx;
		}
		.input{
			margin-top: 20rpx;
			background: white;
			border-radius: 10rpx;
			height: 60rpx;
		}
		.tips{
			color: red;
			font-size: 24rpx;
			margin-top: 20rpx;
		}
		.next{
			margin-top: 60rpx;
			height: 80rpx;
			background: white;
			border: 1rpx solid #999;
			color: #FF0025;
			//border-radius: 10rpx;
			justify-content: center;
			display: flex;
			align-items: center;
		}
	}
	
</style>